/*Group 04
José Renato da Silva Bonatelli 7288964
Matheus Martins Teixeira 7277482
Rafael de Paula Pinto Paravia 71522567*/

/*Calculating pi with a sequential approach of the Monte Carlo algorithm*/
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#define totalPoints 1E+9

int main(void)
{
    const unsigned int A = 1664525, C = 1013904223;
    unsigned int i,pointsInCircle,r;
    float x,y;
    r = (time(NULL)); /*Initial seed*/
    for(i=pointsInCircle=0; i<totalPoints; i++)
    {
        r = r*A+C;                          /*Calculating a pseudo-random value*/
        x = (float)r/UINT_MAX;              /*Pseudo-random value between 0 and 1*/
        r = r*A+C;
        y = (float)r/UINT_MAX;
        if(x*x+y*y <=1) pointsInCircle++;   /*Checking if the point is inside the circle area*/
    }
    printf("%.6f\n",(float)(pointsInCircle<<2)/totalPoints); /*Pi = 4*CircleArea/SquareArea*/
    return 0;
}

